package com.example.wecomservice.common.exception;

import com.alibaba.fastjson.JSON;
import com.example.wecomservice.common.contacts.ResponseContacts;
import com.example.wecomservice.pojo.vo.ApiJsonResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Jamin
 * @Date 2023/2/3 14:33
 */
@RestControllerAdvice(annotations = {RestController.class})
public class GlobalExceptionHandler {
    private static final Log logger = LogFactory.getLog(GlobalExceptionHandler.class);

    @ExceptionHandler(BusinessException.class)
    public String handleException(BusinessException e) {
        logger.error("业务异常", e);
        return JSON.toJSONString(new ApiJsonResult(ResponseContacts.FAILED, e.getMessage()));
    }
}
